package cn.kimming.wms.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.kimming.wms.dao.IDepartmentDAO;
import cn.kimming.wms.dao.IEmployeeDAO;
import cn.kimming.wms.domain.Department;
import cn.kimming.wms.domain.Employee;
import cn.kimming.wms.excep.ObjectIsUsedException;
import cn.kimming.wms.query.QueryObject;
import cn.kimming.wms.service.IDepartmentService;

@Service("departmentService")
public class DepartmentServiceImpl implements IDepartmentService{
	
	@Autowired
	private IDepartmentDAO departmentDAO;
	@Autowired
	private IEmployeeDAO employeeDAO;
	
	@Override
	public void save(Department d) {
		departmentDAO.save(d);
	}

	@Override
	public void update(Department d) {
		departmentDAO.update(d);
	}

	@Override
	public void delete(Long id) {
		List<Employee> emps = employeeDAO.listByDeptId(id);
		for (Employee emp : emps) {
			emp.setDept(null);
		}
		departmentDAO.delete(departmentDAO.get(id));
	}

	@Override
	public Department get(Long id) {
		return departmentDAO.get(id);
	}

	@Override
	public List<Department> list() {
		return departmentDAO.list();
	}

	@Override
	public List<Department> query(QueryObject qo) {
		return departmentDAO.query(qo);
	}
	
}
